﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Net.TCP
{
    /// <summary>
    /// 终端集合
    /// </summary>
    public class EndpointCollection
    {
        private NetClientProxy[] _endpointList;

        public EndpointCollection()
        {
            _endpointList = new NetClientProxy[1000];
        }

        public NetClientProxy this[int index]
        {
            get
            {
                return _endpointList[index];
            }
        }

        public int Length
        {
            get
            {
                return _endpointList.Length;
            }
        }

        public void Add(NetClientProxy endpoint)
        {
            lock (this)
            {
                for (int index = 0; index < _endpointList.Length; index++)
                {
                    if (_endpointList[index] == null)
                    {
                        _endpointList[index] = endpoint;
                        break;
                    }
                }
            }
        }

        public void Remove(NetClientProxy endpoint)
        {
            lock (this)
            {
                for (int index = 0; index < _endpointList.Length; index++)
                {
                    if (_endpointList[index] == endpoint)
                    {
                        _endpointList[index] = null;
                        break;
                    }
                }
            }
        }
    }
}
